package com.neolix.watch.util;

import org.joda.time.DateTime;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateTimeUtil {
    public static DateTime now() {
        return new DateTime();
    }

    public static DateTime today() {
        return now().withTimeAtStartOfDay();
    }

    public static DateTime yesterday() {
        return today().minusDays(1);
    }

    public static DateTime tomorrow() {
        return today().plusDays(1);
    }

    public static DateTime thisMonth() {
        return today().withDayOfMonth(1);
    }

    public static DateTime intervalMonthTime(DateTime startTime, int month) {
        return startTime.plusMonths(month);
    }

    public static DateTime formatDataTime(String text) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try {
            Date date = sdf.parse(text);
            return new DateTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return now();
        }
    }

    public static DateTime formatDataTimeOfyyyyMMDD(String text) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            Date date = sdf.parse(text);
            return new DateTime(date);
        } catch (ParseException e) {
            e.printStackTrace();
            return new DateTime(new Date());
        }
    }

    public static boolean isDay() {
        DateTime time = DateTime.now();
        return time.getHourOfDay() >= 6 && time.getHourOfDay() < 19;
    }

}
